package hcs.ops.func;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

public class Hcs_Billing {

	public void das(WebDriver driver, String pin){
		
		driver.manage().window().maximize();
		driver.findElement(By.xpath("//a[@href='/pba/pbaHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select action = new Select(driver.findElement(By.xpath("//table[@id='results']/tbody/tr/td[8]/select")));
		action.selectByVisibleText("Discharge Patient");
		driver.findElement(By.xpath("//table[@id='results']/tbody/tr/td[9]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@id='dischargeType2']")).click();
		driver.findElement(By.xpath("//input[@id='submitFormButton']")).click();
		driver.findElement(By.xpath("//div[@id='RoomBoardPostingPopup']/div[2]/input[1]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		System.out.println("Patient DAS Discharged.");
		
		
	}
	
	public void regular(WebDriver driver, String pin){
		
		driver.manage().window().maximize();
		driver.findElement(By.xpath("//a[@href='/pba/pbaHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select action = new Select(driver.findElement(By.xpath("//table[@id='results']/tbody/tr/td[8]/select")));
		action.selectByVisibleText("Discharge Patient");
		driver.findElement(By.xpath("//table[@id='results']/tbody/tr/td[9]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@id='dischargeType1']")).click();
		driver.findElement(By.xpath("//input[@id='submitFormButton']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@name='formAction']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@name='skipButton']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='btnSkip']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='skipBtn']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@name='submitButton']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@id='cashPaymentMode1']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		String payment = driver.findElement(By.xpath("//span[@id='totalAmountDue']")).getText();
		System.out.println("Amount Due: "+ payment);
		if(payment.contains(",")){
			payment = payment.replaceAll(",","");
		}
		driver.findElement(By.xpath("//input[@id='cashBillAmount']")).sendKeys(payment);
		driver.findElement(By.xpath("//input[@value='Proceed with Payment']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@id='admissionDoctorsPayment0.pfPayment']")).clear();
		driver.findElement(By.xpath("//input[@id='admissionDoctorsPayment0.pfPayment']")).sendKeys("100");
		driver.findElement(By.xpath("//input[@id='cashPaymentMode1']")).click();
		driver.findElement(By.xpath("//input[@id='cashBillAmount']")).sendKeys("100");
		driver.findElement(By.xpath("//input[@value='Proceed with Payment']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@value='Go To Landing Page']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}
	
	public void generate_unofficial_soa(WebDriver driver, String pin){
		
		driver.manage().window().maximize();
		driver.findElement(By.xpath("//a[@href='/pba/pbaHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@id='optAll']")).click();
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select action = new Select(driver.findElement(By.xpath("//table[@id='results']/tbody/tr/td[8]/select")));
		action.selectByVisibleText("Generation of SOA");
		driver.findElement(By.xpath("//table[@id='results']/tbody/tr/td[9]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@value='Print Unofficial SOA']")).click();
		driver.findElement(By.xpath("//input[@id='perDeptRadio']")).click();
		driver.findElement(By.xpath("//input[@id='showHeader']")).click();
		driver.findElement(By.xpath("//input[@name='_submit']")).click();
		
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}
	
	public void cancel_or(WebDriver driver, String pin){
		
		driver.manage().window().maximize();
		driver.findElement(By.xpath("//a[@href='/pba/pbaHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//a[@href='/pba/pbaDocumentSearch.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		Select doc_type = new Select(driver.findElement(By.xpath("//select[@id='documentTypes']")));
		doc_type.selectByVisibleText("OFFICIAL RECEIPT");
		Select search_option = new Select(driver.findElement(By.xpath("//select[@id='searchOptions']")));
		search_option.selectByVisibleText("PIN");
		
		driver.findElement(By.xpath("//input[@id='textSearchEntry']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@id='actionButton']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//tbody[@id='orTableBody']/tr/td[7]/div[2]/a")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		Select cancel = new Select(driver.findElement(By.xpath("//select[@id='selectCancellationReason']")));
		cancel.selectByVisibleText("CANCELLATION - OR / PAYMENT");
		
		driver.findElement(By.xpath("//input[@value='Submit']")).click();
		System.out.println("Please manually cancel the OR in HCS");
	}
}
